{extend name="public/base" /}
{block name="title"}编辑文章{/block}
{block name="content"}
<div class="layui-fluid">
  <div class="layui-row layui-col-space15">
    <div class="layui-col-md12">
      <div class="layui-card">
        <div class="layui-card-header"><a href="javascript:history.back(-1)" class="layui-btn asuma-btn-header layui-btn-primary layui-btn-sm"><i class="layui-icon layui-icon-left"></i>返回</a>编辑文章</div>
        <div class="layui-card-body" pad15>
          <form class="layui-form" lay-filter="">
            <div class="layui-form-item">
                <label class="layui-form-label">标题</label>
                <div class="layui-input-block">
                    <input type="text" name="title" lay-verify="required" value="{$info.title}" placeholder="请输入标题" autocomplete="off" class="layui-input ">
                </div>
            </div>

            <div class="layui-form-item">
              <label class="layui-form-label">文章内容</label>
              <div class="layui-input-block">
                {include file="public/ueditor" name="content" content=' '}
              </div>
            </div>

            <div class="layui-form-item">
              <label class="layui-form-label">所属栏目</label>
              <div class="layui-input-block" style="z-index: 1001;">
                <select name="column"  lay-verify="required" >
                    <option value="">请选择</option>
                  {volist name="column" id="vo"}
                    <option value="{$vo.id}" {if condition="$info['column_id'] == $vo['id'] "} selected {/if}>{$vo.name}</option>
                  {/volist}
                </select>
              </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">发布人/作者</label>
                <div class="layui-input-block">
                    <input type="text" name="author" lay-verify="required" value="{$info.author}" placeholder="请输入发布人" autocomplete="off" class="layui-input ">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">摘要</label>
                <div class="layui-input-block">
                    <input type="text" name="sub_title" lay-verify="required" value="{$info.sub_title}" placeholder="请输入摘要" autocomplete="off" class="layui-input ">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">状态</label>
                <div class="layui-input-block">
                    <input type="checkbox" name="status" lay-skin="switch" lay-text="发布|隐藏" value="1" {$info.status == 1 ? 'checked=""' : '' }>
                </div>
            </div>

            <div class="layui-form-item">
              <div class="layui-input-block">
                <input type="hidden" name="id" value="{$info.id}">
                <input type="hidden" name="{:config('this.form_token')}" value="{:token()}" />
                <button class="layui-btn layui-btn-asuma" lay-submit lay-filter="setmyinfo" data-url="{:route('editArticles')}">修改</button>
                <a href="javascript:history.back(-1)" class="layui-btn layui-btn-primary">返回</a>
              </div>
            </div>
          </form>
        </div>
      </div>
    </div>
  </div>
</div>
{/block}
{block name="footjs"}
<script>
  layui.use(['form'], function(){
    var form = layui.form;

    UE.getEditor('editorContainer').addListener('blur', function(editor){
      if($('input[name=sub_title]').val() == ''){
        var content = ue.getContentTxt()
        $('input[name=sub_title]').val(content.slice(0,197) + '...')
      }
    });

    form.on('submit(setmyinfo)', function(obj){
      var url = $(obj.elem).data('url')
      var field = obj.field
      $.post(url, field, function(res){
        if(res.code == 1){
          layer.msg('修改成功', {icon: 1}, function(){
            
            window.history.back(-1);
          })
        }else{
          layer.msg(res.result, {icon: 5});
        }
      }, 'json')

      return false;
    })

  })
</script>
<script type="text/javascript">
  $(function(){
    var content = '{$info["content"]|raw}';
    ue.addListener("ready", function () {  
        ue.setContent(content);// editor准备好之后才可以使用
    });
  })
</script>
{/block}